<!-- 管理员用户组新增和编辑页面 -->
<extend name="Public/layout" />
<block name="body">
    <style>
        .checkbox_{ margin:3px 6px; height:30px; line-height:30px; padding-left:5px; }
        .bd .checkbox_{ font-weight:100; margin-right: 20px; }
        .hd{ background:#ecf0f5; }
        .fr{ float:right !important;margin-top:14px;right:20px; }
        .rule_check{ border-bottom: 1px dashed #e5e5e5; padding:5px 0; }
        .rule_check:last-child{ border:none; }
        .auth_title{ margin-left:5px; }
        .child_row{ padding-left:20px; display: block; }
    </style>

    <div class="nav-tabs-custom flat">
        <ul class="nav-tabs nav">
            <li class="active"><a href="javascript:;">访问授权</a></li>
            <li><a href="{$categoryUrl}" class="pjax">分类授权</a></li>
            <li class="fr" style="margin:2px 0 0 0;"> <a>{$groupName}</a> </li>
        </ul>
        <div class="tab-content">
            <!-- 访问授权 -->
            <div class="tab-pane active">
                <form action="" enctype="application/x-www-form-urlencoded" method="POST" class="form-horizontal auth-form box-body ajax-form" style="display:block;">
                    <volist name="node_list" id="node" >
                        <dl class="checkmod box-body" style="border:1px solid #ccccd0;border-radius: 2px;padding:0px;">
                            <dt class="hd">
                            <label class="checkbox_"><input class="auth_rules rules_all" type="checkbox" name="rules[]" value="<?php echo $main_rules[$node['url']] ?>"><span class="auth_title">{$node.title}</span></label>
                            </dt>
                            <dd class="bd">
                            <present name="node['child']">
                                <volist name="node['child']" id="child" >
                                    <div class="rule_check">
                                        <div>
                                            <label class="checkbox_">
                                                <input class="auth_rules rules_row" type="checkbox" name="rules[]" value="<?php echo $auth_rules[$child['url']] ?>"/><span class="auth_title">{$child.title}</span>
                                            </label>
                                        </div>
                                        <notempty name="child['operator']">
                                            <span class="child_row">
                                                <volist name="child['operator']" id="op">
                                                    <label class="checkbox_">
                                                        <input class="auth_rules rules_node" type="checkbox" name="rules[]" value="<?php echo $auth_rules[$op['url']] ?>"/><span class="auth_title">{$op.title}</span>
                                                    </label>
                                                </volist>
                                            </span>
                                        </notempty>
                                    </div>
                                </volist>
                            </present>
                            </dd>
                        </dl>
                    </volist>

                    <div class="tab-footer text-center">
                        <button type="submit" class="btn btn-flat _dt_btns_  btn-primary"><i class="fa fa-save"></i> 保存</button> 　
                        <button  class="btn btn-default btn-flat" onclick="javascript:history.back();return false;" data-dismiss="modal"><i class="fa fa-ban"></i> 取消</button>&nbsp;&nbsp;
                    </div>
                    <script>
                        var ajaxForm = function(formEl){
                            formEl.submit(function(){
                                var lock = false;
                                if(lock){
                                    return false;
                                }
                                lock = true;
                                $.ajax({
                                    'url':formEl.attr('action'),
                                    'type':formEl.attr('method'),
                                    'data':formEl.serialize(),
                                    'dataType':'json',
                                    'success':function(info){
                                        if(info.status){
                                            popup.tip(info.info);
                                        }else{
                                            popup.alert(info.info);
                                        }
                                    },
                                    'error':function(){
                                        popup.alert('系统错误');
                                    },
                                    'complete':function(){
                                        lock = false;
                                    }
                                });
                                return false;
                            });
                        };
                        ajaxForm($('.ajax-form'));
                    </script>
                </form>
            </div>

            <!-- 成员授权 -->
            <div class="tab-pane"></div>

            <!-- 分类 -->
            <div class="tab-pane"></div>
        </div>
    </div>

	<script type="text/javascript" charset="utf-8">
        //+function ($) {
            var rules = [{$this_group.rules}];
            $('.auth_rules').each(function () {
                if ($.inArray(parseInt(this.value, 10), rules) > -1) {
                    $(this).prop('checked', true);
                }
                if (this.value == '') {
                     $(this).closest('span').remove();
                }
            });

            var els = $('input[name="rules[]"]');

            //全选节点
            $('.rules_all').on(' ifChanged', function () {
                $(this).closest('dl').find('dd').find('input').prop('checked', this.checked);
                els.iCheck('update');
            });

            $('.rules_row').on('ifChanged', function () {
                $(this).closest('.rule_check').find('.child_row').find('input').prop('checked', this.checked);
                p1c(this);
                els.iCheck('update');
            });

            $('.rules_node').on('ifChanged', function () {
                p2c(this);
                els.iCheck('update');
            });

            var p1c = function(el){
                var p1 = $(el).closest('dl').find('.rules_all');
                if(el.checked){
                    p1.prop('checked',el.checked);
                }else{
                    if(!$(el).closest('dd').find('.rules_row:checked').length){
                        p1.prop('checked',el.checked);
                    }
                }
            }

            var p2c = function(el){
                var p2 = $(el).closest('.rule_check').find('.rules_row');
                if(el.checked){
                    p2.prop('checked',el.checked);
                    p1c(p2[0]);
                }else{
                    if(!$(el).closest('.child_row').find('.rules_node:checked').length){
                        p2.prop('checked',el.checked);
                        p1c(p2[0]);
                    }
                }
            }

            $('.rules_row').trigger('ifChanged');

        //}(jQuery);
    </script>
</block>

